<template>
	<div class="p-container" v-title data-title='动态列表'>
		<div class="dynamicInfo" v-for="(item, index) in items" v-on:click="toDetail(item.id)" :key="index" @click="toDetail(item.id)">
			<span class="title" v-html="item.title"></span>
			<img v-if="item.imgUrl" :src="item.imgUrl" />
			<!-- <span v-if="item.content" v-html="item.content"></span> -->
			<div style="width: 100%;text-align:right;margin: 10px 0 5px 0;color:#999999;">
				{{item.updateTime}}
			</div>
		</div>
	</div>
</template>
<style scoped>
	.p-container {background-color: #FFF;min-height: 100vh;color: #000;padding: 20px 20px;}
	.dynamicInfo {padding-bottom: 10px;border-bottom: 1px solid #ddd;margin-bottom: 10px;}
	.dynamicInfo .title{font-size: 14px;line-height: 40px;font-weight: bold;}
	.dynamicInfo img {width: 100%;height: 130px;padding-bottom: 10px;}
</style>
<script>
	import MugenScroll from 'vue-mugen-scroll'
	export default {
		components: {
			MugenScroll
		},
		data() {
			return {
				items: [],
				premisesId: this.$route.params.id,
				params: {
					pageSize: 20,
					pageNo: 0
				},
				loading: false
			}
		},
		mounted: function() {
			this.fetchData();
			$("#goble_menu_div").hide();
		},
		methods: {
			fetchData() {
				var _self = this;
				_self.loading = true;
				var body = {};
				body.params = {premisesId:_self.$route.params.id};
				var url = _self.utilHelper.apiUrl + "/api/getPremisesDynamicList";
				_self.$http.post(url,body).then((response) => {
					_self.loading = false;
					let premisesDynamicList = [];
					for (let index = 0; index < response.body.data.length; index++){
						premisesDynamicList.push(response.body.data[index]);
					}
					if(premisesDynamicList && premisesDynamicList.length > 0) {
						premisesDynamicList.forEach(premisesDynamic => {
							let title = premisesDynamic.title;
							if(title.length > 20) {
								premisesDynamic.title = title.substring(0,20)+'...'
							}
							// let content = premisesDynamic.content;
							// if(content.indexOf('<img') != -1) {
							// 	var imgReg = /<img.*?(?:>|\/>)/gi;
							// 	var srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i;
							// 	var arr = content.match(imgReg); 
							// 	premisesDynamic.imgUrl = arr[0].match(srcReg)[1];
							// 	content = content.replace(imgReg,'');
							// 	if(content && content.length > 20) {
							// 		content = content.substring(0, 20) + '...'
							// 	}
							// 	premisesDynamic.content = content
							// }
							premisesDynamic.updateTime = premisesDynamic.updateTime.split(' ')[0]
							console.info("++++"+premisesDynamic.title);
							_self.items.push(premisesDynamic);
						});
					}
				});

			},
			toDetail(id){
				this.$router.push({
					path: '/dynamicDetail/'+id
				})
			}
		}
	}
</script>